<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>权限列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__COMMON__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">权限管理</a>
        <a>
          <cite>权限列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <xblock>
        <!--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <button class="layui-btn" onclick="x_admin_show('添加权限','{:url("admin/Rule/add")}',500,400)"><i class="layui-icon"></i>添加权限</button>
        <span class="x-right" style="line-height:40px">共有数据：{$list|count} 条</span>
      </xblock>
      <table class="layui-table"  lay-filter="mytable">
        <thead>
          <tr>
            <!--<th lay-data="{type:'checkbox', width:60}">-->

            <!--</th>-->
            <th lay-data="{field:'id', width:80}">ID</th>
            <th lay-data="{field:'title'}">权限名称</th>
            <th lay-data="{field:'name'}">规则名</th>
            <th lay-data="{field:'status', width:150}">状态</th>
            <th lay-data="{field:'caozuo', width:200}">操作</th>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
          <tr>
            <!--<td>-->
              <!--<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>-->
            <!--</td>-->
            <td>{$vo.id}</td>
            <td>{$vo.level|str_repeat="——",###}{$vo.title}</td>
            <td>{$vo.name}</td>
            <td class="td-status">
              <input type="checkbox" name="switch" {eq name="vo.status" value="1"}checked{/eq} value="{$vo.id}" lay-skin="switch" lay-filter="status" lay-text="开|关">
            </td>
            </td>
            <td class="td-manage">
              <a onclick="member_stop(this,'{$vo.id}')" href="javascript:;"  title="启用">
                <i class="layui-icon">&#xe601;</i>
              </a>
              <a title="编辑" class="layui-btn layui-btn-default layui-btn-xs"  onclick="x_admin_show('编辑','{:url("admin/Rule/edit",["id"=>$vo.id])}',500,400)" href="javascript:;">
                <i class="layui-icon">&#xe642;编辑</i>
              </a>
              <a title="删除" class="layui-btn layui-btn-danger layui-btn-xs" onclick="member_del(this,'{$vo.id}')" href="javascript:;">
                <i class="layui-icon">&#xe640; 删除</i>
              </a>
            </td>
          </tr>
        {/volist}
        </tbody>
      </table>
    </div>
    <script>
      var table;
      layui.use('table', function(){
          table= layui.table;
          //转换静态表格
          table.init('mytable', {
               id:"mytable"
              ,limit:2000
              ,height: 500 //设置高度
          });
      });

      layui.use('form',function(){
          var form= layui.form;
          form.on('switch(status)', function(data){
              var datas={};
              if(data.elem.checked){
                  datas={id:data.value,status:1};
              }else{
                  datas={id:data.value,status:0};
              }
              $.post("{:url('admin/Rule/setstatus')}",datas,function(res){
                  layer.msg(res.msg,{time:1000});
              },'json');
          });
      });
      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $.post("{:url('admin/Rule/delete')}",{id:id},function(res){
                  layer.msg(res.msg,{time:1000},function(){
                      if(res.code==1){
                          $(obj).parents("tr").remove();
                      }
                  });
              },'json');

          });
      }



      function delAll (argument) {

       var checkStatus = table.checkStatus('mytable');
       var ids=new Array(),key;
        for(key in checkStatus.data){
            ids.push(checkStatus.data[key].id);
        }
        ids=ids.join(",");
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/Rule/delete')}",{id:ids},function(res){
                layer.msg(res.msg,{time:1000},function(){
                    if(res.code==1){
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }
                });
            },'json');
        });
      }
    </script>

  </body>

</html>